package com.cloud.mybatis.config;

import com.cloud.core.constant.SecurityConstants;
import com.cloud.core.entity.base.LoginUser;
import com.cloud.core.entity.permit.UserDeptRoleScope;

import java.util.*;

public class LoginHolder {
    public static HashSet<String>  mapperFunSet = new HashSet<>();
    private static final ThreadLocal<HashMap<String,Object>> securityContext = new ThreadLocal<HashMap<String,Object>>();
    private static final ThreadLocal<LinkedHashMap<String,Object>> permitContext = new ThreadLocal<LinkedHashMap<String,Object>>();

   public static void setMapperFuns(String url) {
       mapperFunSet.add(url);
   }
    public static void clear() {
        securityContext.remove();
    }
    public static void setContext(HashMap<String,Object> context) {
        securityContext.set(context);
    }
    public static void setRoleScope(LinkedHashMap<String,Object> data) {
        permitContext.set(data);
    }
    public static LinkedHashMap<String,Object> getRoleScope() {
      return   permitContext.get();
    }
    public static LoginUser getLoginUser() {
        if(securityContext.get() != null) {
            return (LoginUser) securityContext.get().get(SecurityConstants.USER);
        }
        return null;
    }

    public static Object getLanguage() {
        if(securityContext.get() != null) {
            return  securityContext.get().get(SecurityConstants.ACCEPT_LANGUAGE);
        }
        return null;
    }
}
